Friday, July 29, 2016

Presenter / Laser pointer IOT DIY (5)

Added Infrared sensor and IR led to the IR presenter / laser pointer.
With the IR led this device can transmit IR codes and
with the IR sensor this small device with the ESP8266 can now also
- react to IR codes
- capture IR codes from remote controls


Current configuration of IOT Laser pointer / presenter:

' PinInit.bas
' JanJeronimus 2016
cls
' All pin variables
' (Orderd as print layout)

' Pin Button1 16 GPIO16
let PinButton1 = 16

' Pin IRin  14 GPIO14 / IR receive
let PinIRin = 14

' Pin IRsend 12 GPIO12 / RGB Green / IR send
let PinIRsend = 12

' Pin... 13 GPIO13 / RGB Blue

' PinLaser    5 GPIO4
let PinLaser = 5

' PinDHT11    4  GPIO5
PinDHT11 = 4

' Pin Reed / Button4 0 GPIO0
let PinReed = 0

' Pin Shake / Button5 2 GPIO2
let PinShake = 2

' PinBuzzer  15  GPIO15   /  RGB Red
PinBuzzer = 15

Device = "ESPD01"
' Other side of Button1-5 other signal connected to GND
' With DIP switches all can be connected to VCC or (and!!!) GND

' To save power consumption DHT11 power can be switched off with DIP switches

end 

On this blog you can find  a program for reading the IR sensor. published some time ago,
The updated (quick and dirty) version below has two buttons on the screen
CLR       - Start again (Clean up the screen)
                     ( yes it is 'dirty' and spoils the return stack, however it works )
MARK  - Print a star to the output as marker.
In the output is also a timestamp using the time() function  ( not the local time .. )

' IrRec2.bas
' JanJeronimus 2016
[AGAIN]
cls
html | <h1>IR</h1> |
html | This is the IR receive program <br> |
ir.recv.setup( 14 )
button "CLS" , [AGAIN]
button "MARK" , [MARK]
irbranch [DoIR]
html | <h2> Testing IR input</h2> |
wait

[MARK]
html | * |
wait

[DoIR]
html "<BR>IR received : " & ir.recv.full( ) & " : " & time()
returngui

return

end

Thursday, July 28, 2016

ESP8266 Input GPIO pins 4 and 5 not oke

One of my ESP8266 project did not work as expected. For the ESP8266 i used a module as below. In this project GPIO4 and GPIO5 where used as input. I made changes to the ESP8266Basic program, did measurements on the sensors....
Finally i removed the module from my project and replaced it with another module. The project worked as expected!
I tested the 'bad' module and it turned out that GPIO4 and GPIO4 on this module could not be used for input signal any more. Using GPIO4 and GPIO5 for output was no problem.
When connecting the pin (with a button) to ground the little red leds show if if the pin is connected to ground.
The input signal read by the ESP8266Basic program is always 0. On a similar 'good' module GPIO4 and GPIO5 are 1 if not connected and 0 if connected to ground.
Don't know is if the input circuit is destroyed during the life of this module or this is a software issue. Plan with this module is to use in in another project where GPIO4 and GPIO5 are used as output.















Wednesday, July 27, 2016

Hacking USB power socket

Hacking a USB power socket.
For less than 7 euro's i bought this power socket with 220V and USB (inbouw stopcontact met USB aansluiting) at the Action in Almere (The Netherlands).


On Aliexpress you can find similar wall power sockets with USB

 If opening this socket at the front (to pace it on the wall) you will see this:
It is always nice to have USB power ( e.g. for home automation projects) and i also wanted to know if it is easy to modify the circuit to control the 220V socket with a relay.
I decided to open it on the backside, here are some photos's

As i already expected these is not much space to interrupt the 220 Volt power circuit safe. This to add a relay for controlling the main power. Finally i decided only to add two wires, and make a hole to tap the (low voltage) USB power and bringing it to back of the wall socket for powering a (hidden) IOT device.

Tuesday, July 26, 2016

ESP8266 Floor mat sensor alarm

Today a picture of an alarm step mat (Conrad 751913 bought some years ago)  with, recently added, a long wire and a connector.
The floor mat is somewhere under a carpet in my house. The connector is plugged in a ESP8266 module.
This is not a detailed project, only for inspiration and a message to inform you that my carpet is upgraded to an IOT device.
In the first version ESP8266 GPIO pins are connected to
- Mat sensor line
- Security / tampering wire (from cable, mat) 
- Buzzer (local alarm; Disadvantage this reveals where the module is hidden)
- Shock/Vibration/Tilt sensor (detect moving or tampering of the ESP8266 module) 
Perhaps later i add:
- IR sensor for infrared remote control (switch it on/off or "panic button signal"). Current only by Wifi / Smartphone)
- Tampering (opening of the ESP8266 module if this is in a more permanent 'safe" box) 
- External power sensor.  If external power is missing the module runs on backup power. If the module knows this it can react ( Send message , sound buzzer)
- Panic button (this also reveals the module)
 

Monday, July 25, 2016

IR codes remote control 1

List of IR codes transmitted by
one of my IR remote controls
 received on ESP8266 with ESP8266 Basic.

(A cheap "China remote" with
 text on bottom "Car MP3". )

Display on remote

CH-
e318261b:UNKNOWN:32
CH
511dbb:UNKNOWN:32
CH+
ee886d7f:UNKNOWN:32
PREV
52a3d41f:UNKNOWN:32
NEXT
d7e84b1b:UNKNOWN:32
PLAY/PAUSE
20fe4dbb:UNKNOWN:32
VOL-
f076c13b:UNKNOWN:32

VOL+
a3c8eddb:UNKNOWN:32
EQ
e5cfbd7f:UNKNOWN:32
0
c101e57b:UNKNOWN:32
100+
97483bfb:UNKNOWN:32
200+
f0c41643:UNKNOWN:32
1
9716be3f:UNKNOWN:32
2
3d9ae3f7:UNKNOWN:32
3
6182021b:UNKNOWN:32
4
8c22657b:UNKNOWN:32
5
488f3cbb:UNKNOWN:32
6
449e79f:UNKNOWN:32
7
32c6fdf7:UNKNOWN:32
8
1bc0157b:UNKNOWN:32
9
3ec3fc1b:UNKNOWN:32

ESP8266Basic variables

IR_CHminus = "e318261b:UNKNOWN:32"
IR_CH = "511dbb:UNKNOWN:32"
IR_CHplus = "ee886d7f:UNKNOWN:32"
IR_PREV = "52a3d41f:UNKNOWN:32"
IR_NEXT = "d7e84b1b:UNKNOWN:32"
IR_PLAY = "20fe4dbb:UNKNOWN:32"
IR_VOLminus= "f076c13b:UNKNOWN:32"
IR_VOLplus = "a3c8eddb:UNKNOWN:32"
IR_EQ = "e5cfbd7f:UNKNOWN:32"
IR_0 = "c101e57b:UNKNOWN:32"
IR_100plus = "97483bfb:UNKNOWN:32"
IR_200plus = "f0c41643:UNKNOWN:32"
IR_1 = "9716be3f:UNKNOWN:32"
IR_2 = "3d9ae3f7:UNKNOWN:32"
IR_3 = "6182021b:UNKNOWN:32"
IR_4 = "8c22657b:UNKNOWN:32"
IR_5 = "488f3cbb:UNKNOWN:32"
IR_6 = "449e79f:UNKNOWN:32"
IR_7 = "32c6fdf7:UNKNOWN:32"
IR_8 = "1bc0157b:UNKNOWN:32"
IR_9 = "3ec3fc1b:UNKNOWN:32"

Friday, July 22, 2016

Presenter / Laser pointer IOT DIY (4)

This is a picture of the laser pointer / presenter.

I only added one button at the outside of the box. With more buttons the presenter perhaps could be more easy controlled. With only one button you can send different triggers to a program by pressing the button for a long or a short time.
The box is transparent. With this transparent box you can still use the RGB led and the LDR on ESP8266 module.

ESP8266Basic demo program for testing and using the laser pointer:

'   *** UseLaser.bas ***  
'   demo laser pointer
'  2016 -  JanJeronimus

cls
' Pin Button1 16 GPIO16
let PinButton1 = 16

' PinLaser    5 GPIO4
let PinLaser = 5

' Pin Reed / Button4 0 GPIO0
let PinReed = 0

' Pin Shake / Button5 2 GPIO2
let PinShake = 2

u = 0 
' u = use status 

html | <h1>Select item to control the laser</h1> |

html | <br> |
button "Button1", [Button1]
html | <br> |
button "On / Off with Button1", [ButtonT]
html | <br> |
button "Reed", [Reed]
html | <br> |
button "Shake", [Shake]
html | <br><br> |
button "On", [On]
html | <br> |
button "Off", [Off]
html | <br><br> |
button " Exit ", [Exit] 

timer 1000 ,[SetLaser]

wait 

[Button1]
u = PinButton1
wait

[ButtonT]
u = 980
wait

[Reed]
u = PinReed
wait

[Shake]
u = PinShake
wait

[Off]
u = 990
wait

[On]
u = 991
wait

[SetLaser]

' **  GPIO controlling the laser
'  * <30  u is GPIO number

if u < 30 then
io(po,PinLaser, io(pi,u) )
endif

'  ** Status Toggle with Button1
'  * u = 980  On if Button1
'  * u = 981   wait for release button
'  * u = 982  Off if Button1
'  * u = 983   wait for release button
if u = 980 then
 if io(pi,PinButton1) = 0 then
   io(po,PinLaser, io(pi,1) )
   u = 981        ' set status wait for release 
 endif
endif

' if wait for release
if u = 981 then
 if io(pi,PinButton1) = 1 then
   u = 982 
 endif
endif

if u = 982 then
 if io(pi,PinButton1) = 0 then
   io(po,PinLaser, io(pi,0) )
   u = 983        ' set status wait for release3 
 endif
endif

' if wait for release3
if u = 983 then
 if io(pi,PinButton1) = 1 then
   u = 980 
 endif
endif

'  ** Status Toggle
'  * u = 990 - 991 On / Off
if u = 990 then
io(po,PinLaser, io(pi,0) )
endif

if u = 991 then
io(po,PinLaser, io(pi,1) )
endif
wait

end

Besides the laser pointer some things you can do with this hardware:

- Presentation inside the presenter as webpages
- Wifi scan
- A simple alarm that starts if the switch vibration / tilt switch / shaking ball switch to detects if the module is moved with the next program:
- The Alarm can be switched off by pressing the Button1
- Alarm can be switched off with a magnet (using reed contact)
- The Light Detecting Resistor is currently inside the box. I have plans to move the LDR to the outside (on front of the box) for better sensibility.



Plans for modifications and adding other hardware
- Infra red led
- Infra red sensor / detector
- Move LDR outside the box
- Move RGB led outside the box (?)
- A second reed contact ???
- Connector for a headphone or other external devices
- .....

Thursday, July 21, 2016

Presenter / Laser pointer IOT DIY (3)

In this third article about my DIY IOT laser pointer / presenter programming examples/programming ideas to use this presenter / laser pointer.
You can also use the programs from earlier posts that i used to test the hardware with ESP8266Basic

Laser
Buzzer
DHT11
Input signals

1) Button1Laser.bas

A simple program to switch the laser on with Button1.
You need to keep the button pressed to leave the button on:

' Button1Laser.bas
cls
' Pin Laser    5 GPIO4
let PinLaser = 5

' Pin Button1 16 GPIO16
let PinButton1 = 16

html | <h1>Test Laser</h1> |
html | <br> |
html | <br>Use Button1 to control the laser<br> |
button " Exit ", [Exit]
html | <br> |
timer 1000 ,[Button1Chk]
html | <br> |

wait

[Button1Chk]
io(po,PinLaser, io(pi,PinButton1) )

wait

end

2) UseLaser.bas

This program gives a simple webpage to control the laser.
With the buttons [On] and [Off] you can switch the laser On or Off with the web interface.
The three buttons [Button1], [Reed] or [Shake] are to select other input to control the laser.

' UseLaser.bas
cls
' Pin Button1 16 GPIO16
let PinButton1 = 16

' PinLaser    5 GPIO4
let PinLaser = 5

' Pin Reed / Button4 0 GPIO0
let PinReed = 0

' Pin Shake / Button5 2 GPIO2
let PinShake = 2

u = 0

html | <h1>Select item to control the laser</h1> |

html | <br> |
button "Button1", [Button1]
html | <br> |
button "Reed", [Reed]
html | <br> |
button "Shake", [Shake]
html | <br><br> |
button "On", [On]
html | <br> |
button "Off", [Off]
html | <br><br> |
button " Exit ", [Exit]

timer 1000 ,[SetLaser]

wait

[Button1]
u = PinButton1
wait

[Reed]
u = PinReed
wait

[Shake]
u = PinShake
wait

[Off]
u = 990
wait

[On]
u = 991
wait

[SetLaser]

if u < 30 then
io(po,PinLaser, io(pi,u) )
endif

if u = 990 then
io(po,PinLaser, io(pi,0) )
endif

if u = 991 then
io(po,PinLaser, io(pi,1) )
endif
wait

end









Wednesday, July 20, 2016

Presenter / Laser pointer IOT DIY (2)

This blog article describes how i hardware configured my laser pointer / presenter.

PCB board connections (top down component side) are
-  DHT11
-  Buzzer
Button1  (down)      
Button1  (up)  [not connected]
Button2         [not connected yet]
Button3         [not connected yet]
Reed    ( Button4 )
Shake   (Button5)

' The "other side" of the Button1-5 connected to GND with DIP Switches (A) (1).
'  DIP switches all can be connected to GND (1) or (and!!!) VCC (2)

' To save power consumption DHT11 power can be switched off with DIP switches (B)
'  switch (1) VCC and (2) GND

There is one black (GND) female dupont cable that needs to be connected to GND of the ESP module
There are two red VCC female dupont cables one needs to be connected to VCC on the ESP8266 board.

The laser module needs to be connected to the other red VCC female dupont cable.

The other side of the  laser module is directly connected to the ESP8266 module. I used KY-nnn laser modules (  37in1 arduino module kit ) . As some of these modules are wired reverse you need to check yourself if you need to connect S to VCC or to a GPIO  line of the ESP8266.
The ESP8266 module has the following connections.

'  (left)
' -

' Pin ADC is (currently) connected to Light Detecting Resistor

' -

' Pin Button1 16 GPIO16
let PinButton1 = 16

' Pin... 14 GPIO14

' Pin... 12 GPIO12 / RGB

' Pin... 13 GPIO13 / RGB

' VCC (Red)

' (right)
' PinLaser    5 GPIO4
let PinLaser = 5

' PinDHT11    4  GPIO5
PinDHT11 = 4

' Pin Reed / Button4 0 GPIO0
let PinReed = 0

' Pin Shake / Button5 2 GPIO2
let PinShake = 2

' PinBuzzer  15  GPIO15   /  RGB Red
let PinBuzzer = 15

' GND (Black)

I the programming examples i will try to use the same name for the devices and pins. ( PinButton1 , PinDHT11 ... )


Tuesday, July 19, 2016

Presenter / Laser pointer IOT DIY (1)

This week i will dedicate some blog posts to a presenter / laser pointer that i made.
With a laser led module and a battery you can easy make a simple own laser pointer.
 To make it a real IOT laser pointer / presenter i added a ESP8266 module, a button and as a bonus some other spare parts.
The hardware is partly configurable with dupont wires and DIL switches (More hardware details see part 2.)
ESP8266Basic is used to program the module and configure it over Wifi (See part 3 and 4)
The plastic box was a small box containing some nuts and bolts
 bought in an hardware store that i wanted to give a second life.
With superglue i glued the battery pack ( 3x AA ) included with
 my ESP8266 module on the back of the box.
 I made a hole for the laser led, a push button and
 a opening to for the wires of the battery.

I added a little PCB for some other components. For the power i added two dupont wires with female connectors to connect to the ESP8266 unit.

One additional dupont wire with female connectors is added for the Laser led. The other side of the Laser led is connected directly to the ESP8266 module.

For this version i wanted only one pushbutton on the outside of the box. ( Button1 ). As the button that i had in stock had 3 connections ( push and notPushed  and common). I connected pushed and notPushed to a jumper, so perhaps i can use his later on.
On the inside there are 4 more push buttons from top to down
Button2
Button3
Button4  ( Reed )
Button5 ( Shake )
from this button i also connected one side to the jumper.
The other (common) side of the buttons i all connected to a DIL switch with two switches.
Using this switch i can connect this common side of all switched to VCC ( 3.3.V) or all to ground.
(You must keep one of these switches in the Off position, otherwise you will short the power!!)
For a simple version you can also skip this dip switch and connect the common to ground. (If using a similar ESP8266 module).

Parallel to Button5 i added a switch vibration / tilt switch / shaking ball switch to detect if the module is moved.

Parallel to Button4 i added a reed contact switch. With this switch you can detect a magnet. A reed switch is not needed for a presenter / laser pointer but i had one in stock it is a cheap add-on feature.

I added a passive buzzer connected to GND and a jumper.

In stock i also have some DHT11 temperature humidity sensors. They are not expensive so i decided to add one also with a DIL switch to disconnect the DHT11 from the power lines for a "hardware low power mode". (In that case you can not read temperature and humidity!) The signal line of the DHT11 sensor is also connected to a jumper.

The power On / Off switch is deliberate missing. To turn the power off remove the batteries. This prevents accidentally turning of the device and keeping the batteries in a not used device for long time.

.

Monday, July 18, 2016

ESP8266 and PIR sensor (2)



On an earlier blog i posted an article about the ESP8266 and a 5 Volt PIR sensor.
I tested it powering with 3.3 volt.  It did work some times but not reliable. As i needed a PIR sensor in one of my projects (and i did not want to add 5 Volts) a search on internet did give this article using 'my' PIR motion detection sensor:
http://iot-playground.com/blog/2-uncategorised/74-esp8266-wifi-pir-motion-sensor-easyiot-cloud-rest-api
PIR sensor is power by 5V, but if we look at schematic we will see that is's 3.3V internally. Because ESP8266 is 3.3V, we can bypass PIR internal regulator.
Connection after regulator is available at JP1 pin 3. In our case we will connect 3.3V power supply to this point and not to 5V power supply.
See the picture below for my test and yes it will work if the you connect VCC (3.3V) to JP1 pin 3!
(In the picture Signal is connected to the pin labeled GPIO5, in reality this is GPIO4 )





Friday, July 15, 2016

ESP8266 Basic Buzzer Tone

Today a small ESP8266 Basic program to use a Buzzer with the ESP8266 module.

The frequency of two tones can be adjusted with the two sliders
BuzTime is the time between switching to next tone
' BuzzerSiren.bas

cls
let PinBuzzer = 15
' Connect Buzzer to GND and PinBuzzer

let BuzTime = 500

let BuzV0 = 200
let BuzV1 = 300

let t = 0

html | <h1>Test Buzzer</h1> |

html | <br><br>Freq 0 |
button " 0 " , [Sliders0Off]
slider BuzV0 , 0 , 500
button "MAX" , [Slider0MAX]

html | <br><br>Freq 1 |
button " 0 " , [Sliders1Off]
slider BuzV1 , 0 , 500
button "MAX" , [Sliders1MAX]

html | <br><br> |
button " Off " , [Off]

html | <br><br><br> |
button " Exit ", [Exit]

TIMER BuzTime , [LoopPrg]

wait

[Off]
let BuzV0 = 0
let BuzV1 = 0
wait

[Slider0MAX]
let BuzV0 = 500
wait

[Slider0Off]
let BuzV0 = 0
wait


[Slider1MAX]
let BuzV1 = 500
wait

[Slider1Off]
let BuzV1 = 0
wait

[LoopPrg]

if t = 0 then
io(pwo,PinBuzzer,BuzV0)
endif

if t = 1 then
io(pwo,PinBuzzer,BuzV1)
endif

t = t + 1
if t > 1 then
t = 0
endif

wait

[Exit]
io(pwo,PinBuzzer,0)
cls

end


The picture in this post is of a project
is a sneak preview form a project that i want
to publish next week on this blog.
As you perhaps can see it includes a buzzer and
 a ESP8266 and this program will run on it.

Thursday, July 14, 2016

ESP8266 and PIR sensor (1) Not Working (?)


As i have some of these PIR motion detecting sensors and i wanted to know if my (5 - 20 volt) sensor does work with ESP8266 test module.
The spoiler of the story is already in the title.
With the signal to PinPir (I tried several pins), GND and  +Power to VCC ( 3.3 Volts) i tested the ESP8266 with the program below. This program also toggles another led ( PinChk ) every time the timer routine tests PinPIR.
First the PIR sensor seemed to react on movements.The PIR sensor has a jumper for Single or Repeat Trigger and adjustments for Sensitivity and Time delay. I did not want false alarm signals so did more tests. 
My conclusion is this PIR module does not work reliable on 3V3 if connected the standard way ! This is not a big surprise, the specs say you need 5 - 20 Volts!
ESP8266 and PIR sensor (Not working !!)This configuration starts to give false signals after some time especially if you use the (more power consuming) RGB leds and afer a time you can even remove the PIR sensor and get almost the same results as without the PIR sensor.

' PIR test
cls
' Pin Pir 2 GPIO2

let PinPir = 2

' Pin Led    14 GPIO14
let PinLed = 14

' Pin Chk    4 GPIO5
let PinChk = 4

' Switch off the a RGB leds 
io(po,12, io(pi,1) ) ' 12  GPIO12 RGB led GREEN
io(po,13, io(pi,1) ) ' 13  GPIO13 RGB led BLUE
io(po,15, io(pi,1) ) ' 15  GPIO15 RGB led RED

x = 0
html | <h1>Test Pir sensor</h1> |
html | <br> |
html | <br>Pir sensor controls the Led<br> |
button " Exit ", [Exit] 
html | <br> |
timer 60 ,[PirChk]
html | <br> |
wait 

[PirChk]
' toggle PinChk checkled
x = x + 1
io(po,PinChk,x )
if x > 1 then x = 0

io(po,PinLed, io(pi,PinPir) )
wait

[Exit]
io(po,PinLed, io(pi,1) )
end

A negative result is also a result, i decided to publish it for you (and as a reminder for myself). Perhaps a part of the problem is the wiring of my ESP test module, but 3.3 Volt is also below the specs of this PIR module !
But this is not the end of the story. I did a search on the internet (i need a PIR sensor for my project) and found an interesting article about my module...  As i have planned some other things you have to be patient before i can publish my test results.