Posted on Leave a comment

Simple Frankenbot with lights and sound effect


I was inspired by the cute Frankenbot papercraft from Instructables, so I thought why not make it truly alive by giving it some blinking lights and sounds effect. Here is the plan:

– Connect 2 LEDs for the eyes (different colours of course) and only one eye can be on at a time

– Connect 3 LEDs to the chest so that it can run lights left and right

– Play some scary halloween music for the full effect.

So here goes my Frankenbot ready for Halloween.

Step 1. Create the Frankenbot papercraft using the instruction from Instructables.

Step 2. Cut out the eye holes and insert LEDs

Franken bot eyes


I use the recycle LEDs that was joined together with one 220 ohm resistor. Different legs was connected to the same resistor so only one eye will be on at a time, and you will have to switch the polarity to light up the second eye.

Step 3. Prepare the chest holes for LEDs

Chest holesCut out 3 more holes on the chest. It is much easier to cut it out when you had the robot chest disassembled.

Step 4. Prepare the electronics

I am using the recycled electronics from the “Light Activated MP3 player” from the earlier post. You can follow the link to find the instruction on how to build one.

Things to note, the way the light activated will need to be reversed, in this we want the Frankenbot to stay idle when there is sufficient light detected by the sensor, and when the light is off, it will came alive blinking it’s eyes and the chest lights and also playing the horror music at the background. So minor modification to the source code is necessary.

Step 5. Connecting the LEDs

Connecting LEDs

What I had done here is essentially as follows:

– Eyes is connected through pin D2 and D6

– Chest LEDs is connected through pin D3, D4 and D5

So the following additional modification to the code is necessary

const int LDRpin = A0;       // LDR connected to pin A0 const int EyeCommon = 6;    // low = off
const int Eyepin = 2;      // Eye LED pin D23
const int Chest1 = 3;
const int Chest2 = 4;
const int Chest3 = 5;

Step 6. It’s Alive

FrankenbotThere are several final modification to the code is necessary as follows:

In the setup section add the following:

pinMode(LDRpin, INPUT);     // setup LDR
  pinMode(EyeCommon, OUTPUT);
  pinMode(Eyepin, OUTPUT);
  pinMode(Chest1, OUTPUT);
  pinMode(Chest2, OUTPUT);
  pinMode(Chest3, OUTPUT);

in the loop section add the following:

if (ldrStatus <300){
    //digitalWrite(LED_BUILTIN, LOW);
    digitalWrite(EyeCommon, LOW);  // eye LED had different polarity so that 
    digitalWrite(Eyepin, HIGH);	   // only one eyes can be on at one time
    digitalWrite(EyeCommon, HIGH);
    digitalWrite(Eyepin, LOW);
    timeoutTimer ++;
    //Serial.print("LED Light");
    if (DEBUG) Serial.println(timeoutTimer);
    digitalWrite(Chest1, LOW); // chest LED had common cable connected, 	 	
    digitalWrite(Chest2, HIGH); // my common cable is connected to Anode, 
    digitalWrite(Chest3, HIGH);  // so EyeCommon needs to be HIGH
    digitalWrite(Chest1, HIGH);
    digitalWrite(Chest2, LOW);
    digitalWrite(Chest3, HIGH);
    digitalWrite(Chest1, HIGH);
    digitalWrite(Chest2, HIGH);
    digitalWrite(Chest3, LOW);
    digitalWrite(Chest1, HIGH);
    digitalWrite(Chest2, LOW);
    digitalWrite(Chest3, HIGH);
    onStatus = true;
    if (timeoutTimer > 200) {
      if (DEBUG) Serial.println(timeoutTimer);
      timeoutTimer = 0;
      resetCount = 0;

The section above is when the light intensity is low, so we flicker the eyes LED and the chest LEDs. The following section is when the light is high, we only have one eyes turned on.

} else {
    digitalWrite(EyeCommon, LOW);
    digitalWrite(Eyepin, HIGH);
    digitalWrite(Chest1, HIGH);
    digitalWrite(Chest2, HIGH);
    digitalWrite(Chest3, HIGH);    

    timeoutTimer ++;

And don’t forget to upload the scary scene music to the sd card. In this example I put it in the folder “07” and the song is called “001.mp3”

Now upload the code and test it, if all goes well, when you flick the switch your Frankenbot will come alive. Cover the sensor or turn off the lights, it’s eyes should flicker and the chest LED will flicker too.

Enjoy and Happy Halloween!!!

If you like this you can subscribe for frequent update and leave some comments.

Posted on Leave a comment

IoT Gas Sensor with ESP8266

I had been wanting to get the gas sensor working with my ESP8266 as an additional item on the IoT list. So similar to the IoT Temperature sensor from the previous post, I had created the IoT gas sensor using ESP8266.

Using the same idea you don’t have to open port in your router, but leveraging an intermediate layer by publishing the data to a website. Here are the list of components used:

The circuit

We are connecting the Gas sensor analog output to Analog input (AD0) of ESP8266 as shown in the following picture.


The Buzzer is connected to Pin GND and D3.

We will check the sensor via analog to give much better variation, we can also use the Digital output from the sensor, but you will have to calibrate this properly to ensure that it gives the desired trigger when a certain composition of gas was detected. You can use the prototype board to connect them all up and using Arduino interface you can load the code.

If you are not familiar on how to setup the Arduino IDE (integrated development Environment) I had an instructables post that can help you to get started.

The finished connection should look like something below:

IoT Gas Sensor with ESP8266

Now that you have a setup the circuit, there is one more step to setup the Cloud webserver (optional) if you want the sensor to periodically upload the gas reading to the webserver so that you can monitor this remotely.

Assumption: You have a working webserver, and familiar with transferring files to your webserver.

Web server setup

Transfer the content of “” into the root of your webserver. Let’s assume that your webserver is “”

You can put the file in a separate folder, but you need to modify the sketch to point to the correct location of “gasdata_store.php”

In this example we are assuming that the full path to the file are

Once you had uploaded the files, you can test that it is working going to the following link

watch out for the character case as most webserver are case sensitive. If all is working, you should see something that looks like the following:

IoT Gas Data

One more thing you will need to make sure is the file “gas.txt” needs to be writeable, so you need to set the permission of this file to “666” by using the following unix command:

chmod 666 gas.txt

This file is where the sensor data will be uploaded into by the ESP8266.

You can download the webserver scripting using this link.

Uploading the arduino sketch

Now you are ready to upload the sketch code to the ESP8266. You should have 2 files:

  • ESP8266GasSensor.ino
  • mainPage.h
  • settings.h

Put them all in the same folder and open the “ESP8266GasSensor.ino” in the Arduino IDE, then make small modification to the code to point to the correct webserver location shown in the following picture:

Arduino code changes

Modify the line

String weburi = "/gasdata_store.php"

if you didn’t put this file in the root of the webserver, this should point to the correct path of the file. Then compiled and load the sketch to ESP8266. If all goes well you should have a working AP (Access point) from the ESP8266 the first time you run this. The AP’s name is called “ESP-GasSensor”.

Try to connect to this AP using your laptop or mobile phone, then find out what is the ip address that was assigned to you, this can be done using “ipconfig” command in windows or “ifconfig” command if you are in linux or mac. If you are using iPhone you can click on the “i” button next to the ESP-GasSensor that you are connected to.

Open your web browser and point to the ESP-GasSensor Ip address, if you are assigned with as your up, the ESP-GasSensor is have the ip of, so you can point your web browser to

You should be presented with the settings page where you can enter your wifi configuration. Once you had enter your WiFi access point that connects to the internet, tick the “update Wifi Config” check box, and click on “update” to save the settings to the ESP8266.

The ESP8266 will now restart and trying to connect to your WiFi router. If all goes well you should see the gas data being updated to you webserver on a regular interval. In this example you can point your browser to

Congratulations!! if you manage to reach this part. You should give yourself a pat on the back. Now you can tell your friends about the gas sensor that you have.

You can download the full arduino source code here.

Final adjustment

But wait you might want to re-calibrate the sensor alarm to suit your need. This is not just for show, it should trigger and alarm when the threshold of gas reach a certain level. Depends on the type of sensor that you are using you will need to calibrate this. So go get a lighter, and point the lighter towards the sensor, and without lighting the lighter, press the gas release button on the lighter, so the gas will flow to the sensor. This should trip the buzzer. If not then you need to check whether the reading goes up by looking at the webserver. If this is not working then you need to check the connection, the sensor and the buzzer. If all goes well, the buzzer should make a noise. The threshold in the code is set to 100, you should be able to find it in the following section of the code:

double threshold = 100;

Feel free to change the threshold to higher or lower depends on your need. I hope you like this project. If you do please drop me a line, and subscribe to my blog for more projects.


Posted on Leave a comment

Arduino Dice simulator

I was looking at my kids playing snake and ladder tonight, and came an idea in my mind “why don’t I make a dice simulator?”. I already had the LED matrix from the previous post here. So I created the Arduino Dice simulator using my previous circuit.

So I added a permanent button to the circuit that I had using a pull-down resistor of 10K ohm which connects pin 2 to the ground.

Then with little modification to the code as following

// LED matrix with latch 74HC595N
// the program random display the character
// the button is added and the character will only be displayed if after the button is pressed
// added code to simulate a dice

int latchPin = 4; // pis connected to shift registors
int clockPin = 5;
int dataPin = 3;
int pins [8] = {6, 7, 8, 9, 10, 11, 12, 13}; // common cathode pins
int button = 2; // connect button and 10K resistor to GND (normal LOW), the other end to 5V
byte A[8] = {   B00000000, // Letters are defined
                B00011000,// you can create your own
byte B[8] = {0x0, 0x7c, 0x42, 0x42, 0x7c, 0x42, 0x42, 0x7c}; 
byte C[8] = {0x0, 0x3c, 0x42, 0x40, 0x40, 0x40, 0x42, 0x3c};
byte D[8] = {0x0, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7c};
byte E[8] = {0x0, 0x7e, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x7e};
byte F[8]={0x0, 0x7e, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x40};
byte G[8]={0x0, 0x3c, 0x42, 0x40, 0x4e, 0x42, 0x42, 0x3c};
byte H[8]={0x0, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42};
byte I[8]={0x0, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70};
byte J[8]={0x0, 0x7c, 0x4, 0x4, 0x4, 0x4, 0x44, 0x38};
byte K[8]={0x0, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44};
byte L[8]={0x0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7c};
byte M[8]={0x0, 0x42, 0x66, 0x5a, 0x42, 0x42, 0x42, 0x42};
byte N[8]={0x0, 0x42, 0x62, 0x72, 0x5a, 0x4e, 0x46, 0x42};
byte O[8]={0x0, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c};
byte P[8]={0x0, 0x7c, 0x42, 0x42, 0x7c, 0x40, 0x40, 0x40};
byte Q[8]={0x0, 0x3c, 0x42, 0x42, 0x42, 0x4a, 0x44, 0x3a};
byte R[8]={0x0, 0x7c, 0x42, 0x42, 0x7c, 0x48, 0x44, 0x42};
byte S[8]={0x0, 0x3e, 0x40, 0x40, 0x3c, 0x2, 0x2, 0x7c};
byte T[8]={0x0, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10};
byte U[8]={0x0, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c};
byte V[8]={0x0, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18};
byte W[8]={0x0, 0x42, 0x42, 0x42, 0x42, 0x5a, 0x66, 0x42};
byte X[8]={0x0, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x0};
byte Y[8]={0x0, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10};
byte Z[8]={0x0, 0x7e, 0x4, 0x8, 0x10, 0x20, 0x40, 0x7e};
byte X1[8]={0x0, 0x0, 0x18, 0x3c, 0x3c, 0x18, 0x0, 0x0};
byte X2[8]={0x0, 0x20, 0x70, 0x20, 0x4, 0xe, 0x4, 0x0};
byte X3[8]={0x40, 0xe0, 0x40, 0x18, 0x18, 0x2, 0x7, 0x2};
byte X4[8]={0x42, 0xe7, 0x42, 0x0, 0x0, 0x42, 0xe7, 0x42};
byte X5[8]={0x42, 0xe7, 0x42, 0x18, 0x18, 0x42, 0xe7, 0x42};
byte X6[8]={0x66, 0x66, 0x0, 0x66, 0x66, 0x0, 0x66, 0x66};
byte blank[8] = { B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};
long randNumber;
int buttonpressed = 0;
long time = 0; // last time the button pressed
long debounce = 50;

void setup() {
  Serial.begin(9600); // Serial begin
  pinMode(latchPin, OUTPUT); // Pin configuration
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  for (int i = 0; i < 8; i++) { // for loop is used to configure common cathodes
    pinMode(pins[i], OUTPUT);
    digitalWrite(pins[i], HIGH);
  pinMode(button, INPUT);   // set button input 

void loop() {
  // read the button
  buttonpressed = digitalRead(button);
  if (buttonpressed == HIGH && millis() - time > debounce){
    time = millis();
    randNumber = random(1,6);
    for (int k = 0; k < 1000; k++) { // showing each letter for 1 second
  } else {

  // add more letters show method here


void getChar(int num){
  switch (num){
    case 1: display_char(X1); break;
    case 2: display_char(X2); break;
    case 3: display_char(X3); break;
    case 4: display_char(X4); break;
    case 5: display_char(X5);break;
    case 6: display_char(X6);break;

void display_char(byte ch[8]) { // Method do the multiplexing
  for (int j = 0; j < 8; j++) {
    digitalWrite(latchPin, LOW);
    digitalWrite(pins[j], LOW);

    shiftOut(dataPin, clockPin, LSBFIRST, ch[j]);
    digitalWrite(latchPin, HIGH);
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, B00000000); // to get rid of flicker when
    digitalWrite(latchPin, HIGH);
    digitalWrite(pins[j], HIGH);


I hope you enjoyed this short post. You can view the result in the following video

If you like what I post, don’t forget to subscribe.