Thank you python coder. i will check and get back to you if i have any question.pythoncoder wrote: ↑Tue Jun 18, 2019 9:49 amThe Wiki http://wiki.micropython.org/Home has links to drivers for a variety of devices. You can also search this forum.
How to switch on a electric bulb with ESP8266 board?
-
- Posts: 51
- Joined: Wed May 08, 2019 10:54 am
Re: How to switch on a electric bulb with ESP8266 board?
-
- Posts: 51
- Joined: Wed May 08, 2019 10:54 am
Re: How to switch on a electric bulb with ESP8266 board?
Hi , i am trying to blink inbuilt led only once if the level value is less than 10. with below code i am able to blink once.but when the level value increases more than 10 and reduces less then 10 led is not blinking. can someone help me how to achieve this ?
Note:- if i include i=0 inside while loop, i value in if condition treating as zero and it is not increasing.
output :
----------
32
30
10
9
blink
7
6
40
33
23
11
9
8
4
5
32
Note:- if i include i=0 inside while loop, i value in if condition treating as zero and it is not increasing.
Code: Select all
from machine import Pin,ADC
import time
adc=ADC(0)
pin=Pin(14,Pin.OUT)
i=0
while True:
level=adc.read()
print(level)
if level<10 and i==0:
print('blink')
pin.on()
time.sleep(5)
pin.off()
i=i+1
time.sleep(1)
----------
32
30
10
9
blink
7
6
40
33
23
11
9
8
4
5
32
Re: How to switch on a electric bulb with ESP8266 board?
You must reset i=0 if level raises again to 10 and more.e.g.
Code: Select all
from machine import Pin,ADC
import time
adc=ADC(0)
pin=Pin(14,Pin.OUT)
i=0
while True:
level=adc.read()
print(level)
if level<10 and i==0:
print('blink')
pin.on()
time.sleep(5)
pin.off()
i=i+1
if level >= 10:
i = 0
time.sleep(1)
-
- Posts: 51
- Joined: Wed May 08, 2019 10:54 am
Re: How to switch on a electric bulb with ESP8266 board?
Thank you Robert. Now logic is working fine.Roberthh wrote: ↑Sat Jun 22, 2019 7:58 pmYou must reset i=0 if level raises again to 10 and more.e.g.Code: Select all
if level >= 10: i = 0 time.sleep(1)
-
- Posts: 51
- Joined: Wed May 08, 2019 10:54 am
-
- Posts: 51
- Joined: Wed May 08, 2019 10:54 am
Re: How to switch on a electric bulb with ESP8266 board?
typo mistake. now i have changed scenarios from censoriousRajaRamesh wrote: ↑Sun Jun 23, 2019 7:50 amHi Robert, i have a doubt. Logic is working when level<10 and power is on. But what if power off and power is back in midnight. how to handle logic not work in midnight for few censorious?
Hi Robert, i have a doubt. Logic is working when level<10 and power is on. But what if power off and power is back in midnight. how to handle logic not to work in midnight for few scenarios ?
Re: How to switch on a electric bulb with ESP8266 board?
You can control that by the initial value of i 0 or 1. If you want the behaviour to change in certain times, you need to know the real time. But you were at that question before.
-
- Posts: 51
- Joined: Wed May 08, 2019 10:54 am
Re: How to switch on a electric bulb with ESP8266 board?
Hi Robert, yes, i am aware of real time which we need to synchronize with ntptime and for this we need internet. But, i am trying to make the code to work without ntptime. so i thought that there will be a way to handle esp8266 when power is on and off. i see you stated initial value of i 0 or 1. do i need to declare this values in the code to make esp8266 to work when power is on and off ? just assuming. correct me if i am wrong.
-
- Posts: 51
- Joined: Wed May 08, 2019 10:54 am
Re: How to switch on a electric bulb with ESP8266 board?
Hi Robert, After googling and searching in forum i found " DS3231 RTC module which work with battery cell independently " and operate at certain time in remote areas where internet is not available. Now, i need to figure out how to connect DS3231 with ESP8266 and need to build code to get time. could you please share any useful link or code to work with DS3231 if you have any?RajaRamesh wrote: ↑Mon Jun 24, 2019 10:38 amHi Robert, yes, i am aware of real time which we need to synchronize with ntptime and for this we need internet. But, i am trying to make the code to work without ntptime. so i thought that there will be a way to handle esp8266 when power is on and off. i see you stated initial value of i 0 or 1. do i need to declare this values in the code to make esp8266 to work when power is on and off ? just assuming. correct me if i am wrong.
sample DS3231 link :- https://www.amazon.in/Robodo-Electronic ... 285&sr=8-1
Re: How to switch on a electric bulb with ESP8266 board?
You should try the driver made by @pythoncoder https://github.com/peterhinch/micropyth ... ter/DS3231
It was made for PyBoard, ESP8266 and others.
It was made for PyBoard, ESP8266 and others.