How to switch on a electric bulb with ESP8266 board?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: How to switch on a electric bulb with ESP8266 board?

Post by RajaRamesh » Tue Jun 18, 2019 11:17 am

pythoncoder wrote:
Tue Jun 18, 2019 9:49 am
The Wiki http://wiki.micropython.org/Home has links to drivers for a variety of devices. You can also search this forum.
Thank you python coder. i will check and get back to you if i have any question.

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: How to switch on a electric bulb with ESP8266 board?

Post by RajaRamesh » Sat Jun 22, 2019 7:42 pm

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.

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)
output :
----------
32
30
10
9
blink
7
6
40
33
23
11
9
8
4
5
32

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How to switch on a electric bulb with ESP8266 board?

Post by Roberthh » Sat Jun 22, 2019 7:58 pm

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)

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: How to switch on a electric bulb with ESP8266 board?

Post by RajaRamesh » Sun Jun 23, 2019 6:48 am

Roberthh wrote:
Sat Jun 22, 2019 7:58 pm
You 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)
Thank you Robert. Now logic is working fine.

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: How to switch on a electric bulb with ESP8266 board?

Post by RajaRamesh » Sun Jun 23, 2019 7:50 am

Roberthh wrote:
Sat Jun 22, 2019 7:58 pm
You must reset i=0 if level raises again to 10 and more.e.g.
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 work in midnight for few censorious?

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: How to switch on a electric bulb with ESP8266 board?

Post by RajaRamesh » Mon Jun 24, 2019 10:10 am

RajaRamesh wrote:
Sun Jun 23, 2019 7:50 am
Roberthh wrote:
Sat Jun 22, 2019 7:58 pm
You must reset i=0 if level raises again to 10 and more.e.g.
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 work in midnight for few censorious?
typo mistake. now i have changed scenarios from 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 ?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How to switch on a electric bulb with ESP8266 board?

Post by Roberthh » Mon Jun 24, 2019 10:18 am

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.

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: How to switch on a electric bulb with ESP8266 board?

Post by RajaRamesh » Mon Jun 24, 2019 10:38 am

Roberthh wrote:
Mon Jun 24, 2019 10:18 am
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.
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.

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: How to switch on a electric bulb with ESP8266 board?

Post by RajaRamesh » Tue Jun 25, 2019 7:37 am

RajaRamesh wrote:
Mon Jun 24, 2019 10:38 am
Roberthh wrote:
Mon Jun 24, 2019 10:18 am
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.
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.
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?

sample DS3231 link :- https://www.amazon.in/Robodo-Electronic ... 285&sr=8-1

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How to switch on a electric bulb with ESP8266 board?

Post by Roberthh » Tue Jun 25, 2019 10:23 am

You should try the driver made by @pythoncoder https://github.com/peterhinch/micropyth ... ter/DS3231
It was made for PyBoard, ESP8266 and others.

Post Reply