A
A
Andrey2018-06-22 13:49:15
Electronics
Andrey, 2018-06-22 13:49:15

How to control the load in the ESP8266 with this connection scheme?

Hello radio lovers!
Please tell me, I'm trying to assemble a ball valve control on the ESP8266-01.
Here according to this scheme:
5b2cd3cf261b1708004986.gif
The logic of work is as follows. After applying voltage, the outputs GPIO0, GPIO2 are LOW.
After issuing a command to turn on, GPIO0 is switched to the HIGH state for 5 seconds, and then back to LOW.
While writing / debugging the program, there were diodes at the outputs - everything worked well. (There is no crane yet)
I decided to assemble the circuit - and the following situation turns out. When voltage is applied, on the collectors of transistors (let's call them VT1 and VT2) + 3.3v ... And when the command is given to open / close 0v.
THOSE. It's the other way around.
Somehow it doesn’t turn out logically ...
Tell me, how best to change the scheme or rewrite the logic?
PS. Sorry if this is a stupid question... ESP picked up for the first time two days ago...
Thank you!
Logics:

--WiFi Settup
wifi.setmode(wifi.STATION)
local cfg={}
cfg.ssid="222"
cfg.pwd="111"
wifi.sta.config(cfg)
cfg = nil
collectgarbage()
--Set Pin mode
my_pin_nummber = 3
my_pin_nummber2 = 4
gpio.mode(my_pin_nummber, gpio.OUTPUT)
gpio.mode(my_pin_nummber2,gpio.OUTPUT)
local boolean kran_open = false

 
--Create HTTP Server
http=net.createServer(net.TCP)
 

 function gpio0_off()
   gpio.write(my_pin_nummber, gpio.LOW)
 end
 function zakrit_kran()
   if kran_open  == true then
   gpio.write(my_pin_nummber2, gpio.HIGH)
   tmr.alarm(1,5000, tmr.ALARM_SINGLE, function() gpio.write(my_pin_nummber2, gpio.LOW) end)
   kran_open = false
 else
   print('Kran ZAKRIT')
   end
   end
   
 function ShowKranStatus()
   local string s =''
   if kran_open == true then
     s = 'OPEN'
     return s
   else
     s = 'CLOSE'
     return s
   end
 end
 
   
 
function receive_http(sck, data)    
  local request = string.match(data,"([^\r,\n]*)[\r,\n]",1)
  if request == 'GET /on HTTP/1.1' then
    kran_open = true
    gpio.write(my_pin_nummber, gpio.HIGH)
    tmr.alarm(0,5000, tmr.ALARM_SINGLE, function() gpio.write(my_pin_nummber, gpio.LOW) end)
    --Максимальное значение 6870947
    tmr.register(2,6870947,tmr.ALARM_AUTO,zakrit_kran)
    tmr.start(2)
  end
  if request == 'GET /off HTTP/1.1' then
    --gpio.write(my_pin_nummber, gpio.LOW)
    kran_open = false
    gpio.write(my_pin_nummber2, gpio.HIGH)
    tmr.alarm(3,5000, tmr.ALARM_SINGLE, function() gpio.write(my_pin_nummber2, gpio.LOW) end)
    
  end  
 
  sck:on("sent", function(sck) sck:close() end)
   
  local response = "HTTP/1.0 200 OK\r\nServer: NodeMCU on ESP8266\r\nContent-Type: text/html\r\n\r\n"..
     "<html><title>NodeMCU on ESP8266</title><body>"..
     "<h1>NodeMCU on ESP8266</h1>"..
     "<hr>"..
     "<a href=\"on\">On</a>  ------  <a href=\"off\">Off</a>"..
     --"<p> KRAN OPEN TIME- "..tmr.now(2).."</p>"..
     "<p> KRAN OPEN ? - "..ShowKranStatus().." ! </p>"..
     "</body></html>"
  sck:send(response)
end
 
 
if http then
  http:listen(80, function(conn)
    conn:on("receive", receive_http)
  end)
end
 
print("Started.")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-06-22
@andrey71

You have a circuit where active 0 (LOW). And for some reason the diagram is incomplete. It is not clear what transistors control. According to the rules of circuitry, GND is always switched in loads through an npn transistor or mosfet, and the positive wire may not necessarily be 3.3v.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question