Friday, 28 July 2017

Wi-Fi Enabled bed lamp - Project to teach the kids

In today's world where school is all theory with very little reality to pin it to in our mental model, we decided to try and give some kids as many different experiences as we could as early as possible. Once they get to the theories taught in the classroom they will hopefully have some mental model to connect it with.

This is one of those projects.

The Wi-Fi enabled Bedlamp


4 Kids aged between 7 and 13 and their parents each built their own Bed side lamp. We started off with the woodwork. We encouraged them to do as much of the work themselves, even with the larger machinery (With good and careful adult supervision).
Some kids and dads while doing the woodwork.
The Circuit we built was relatively simple and consisted mostly of just an ESP01 (which has a total of two GPIO's), a relay, a linear voltage regulator (for the 3.3V supply) and a couple of passives, all soldered to some veroboard.

Functional Diagram showing main components
The button was connected to allow for in place programming. With Tx and Rx connected, if you powered the circuit on while holding down the button, the ESP8266 would boot into firmware mode, otherwise it would start-up normally.
Circuit diagram
We printed the image below out and everyone placed their pack of components into the vera board and soldered the bits themselves.
Vera/Strip board component layout
Mom and daughter sorting and placing components on their boards before soldering them.
Mom helping her daughter. Neither have ever built electronics before.
Below are some images of a finished lamp with a perspex/plexiglass bottom to show off the work.
Perspex/Plexiglass bottom cover to see the hard work.

We made use of a 5V USB charger, which was stripped of it's case and had the 5V rail tapped off to power our circuit. This provided a nice opportunity to integrate the original USB charger into the side of the lamp, where your phone will probably be during the night anyway, ;-)
USB charger on the side.
When the lamp is initially turned on in a new network, the lamp comes up as a WiFi access point. Connecting to it opens a web interface allowing you to search, configure and connect to your local Wi-Fi network. Once that is done, your Wi-Fi router should provide the lamp with its own IP address (You can easily find the new IP address by looking on your router configuration page.
Mobile phone UI when connecting to the lamp via Wi-Fi
We wired the relay up to be off while GPIO2 (Also connected to the LED on the module) was on so that it would shine through the clear plastic round bar used to press the power button. This made the on switch glow blue while the light is off. This makes it nice and easy to find the light switch at night.
Light Switch glows when the light is off.
The video below is a really short view of the basic operation of the finished lamp.



As always, I would love to hear your thoughts in the comments below.

Bill of Material

  • LM1117-3,3 3.3V Liear Voltage Regulator
  • 10µF capacitor
  • 100µF Capacitor
  • Momentary push tactile button
  • Mains rated relay with 5V actuator
  • 4 x 3K3Ω Resistor
  • 1N4001 Diode
  • BCM337 NPN transistor
  • ESP-01s ESP8266 module
  • Cheap 5V 1AMP USB charger

Firmware Source Code

/*
 * Copyright 2017 Gineer RnD
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Relay control using the ESP8266 WiFi chip

// Import required libraries
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>

//Room Name
const String RoomName = "Switch";

//Response from Client
String request = "";

// The port to listen for incoming TCP connections 
#define LISTEN_PORT           80

// set pin numbers:
const int buttonPin = 0;    // the number of the pushbutton pin
const int relayPin = 2;      // the number of the SWITCH pin

int relayState = LOW;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers

// Create an instance of the server
WiFiServer server(LISTEN_PORT);
WiFiClient client;

void setup(void)
{  
   // Start Serial
   Serial.begin(115200);
   delay(10);
   Serial.println();
   Serial.println();
   Serial.println();
   Serial.println();

   //initialise WiFi Manager
   WiFiManager wifiManager;

   //first parameter is name of access point, second is the password
   wifiManager.autoConnect("GineerLamp", "secureme");

   pinMode(buttonPin, INPUT);
   pinMode(relayPin, OUTPUT);

   // set initial SWITCH state
   digitalWrite(relayPin, relayState);
  
   Serial.println("");
   Serial.println("WiFi connected");
  
   // Start the server
   server.begin();
   Serial.println("Server started");
  
   Serial.println("You can connect to this Switch at this URL:");
   Serial.print("http://");
   // Print the IP address
   Serial.print(WiFi.localIP());
   Serial.println("/");
  
}

void loop() {
  request = "";
  
  // Handle REST calls
  WiFiClient client = server.available();
  if (client) {
     Serial.println("User connected.");
     while(!client.available()){
          delay(1);
     }
     Serial.print("Request Received:");
     request = client.readStringUntil('\r\n');
     Serial.println(request);
     client.flush();
  }

    //process the request
    if (request.indexOf("/SWITCH=ON") != -1) {
       relayState = HIGH;
    }
    if (request.indexOf("/SWITCH=OFF") != -1) {
       relayState = LOW;
    }

   // read the state of the switch into a local variable:
   int reading = digitalRead(buttonPin);

   // If the switch changed, due to noise or pressing:
   if (reading != lastButtonState) {
     // reset the debouncing timer
     lastDebounceTime = millis();
   }

   if ((millis() - lastDebounceTime) > debounceDelay) {
     // whatever the reading is at, it's been there for longer
     // than the debounce delay, so take it as the actual current state:

     // if the button state has changed:
     if (reading != buttonState) {
       buttonState = reading;

       // only toggle the SWITCH if the new button state is HIGH
       if (buttonState == HIGH) {
         relayState = !relayState;
       }
     }
   }

   digitalWrite(relayPin, relayState);

   // save the reading.  Next time through the loop,
   // it'll be the lastButtonState:
   lastButtonState = reading;

  if (client) {
      client.println("HTTP/1.1 200 OK");
      client.println("Content-Type: text/html; charset=UTF-8");
      client.println("");
      client.print("<!DOCTYPE html><html><head><title>");
      client.print(RoomName);
      client.print(": Gineer.Home.SmartSwicth</title><style>body {background-color: black;color: white;text-align: center;}#switchSlider {display: inline-block;left: 28px;position: relative;border: 4px solid gray;width: 40px;height: 120px;vertical-align: central;}#switchToggle {display: inline-block;left: -30px;position: relative;border: 4px solid gray;width: 60px;height: 20px;vertical-align: central;}#switchSlider.off {background-color: silver;}#switchToggle.off {top: -20px;background-color: silver;}#switchSlider.on {background-color: yellow;}#switchToggle.on {top: -80px;background-color: yellow;}</style></head><body><h1>");
      client.print(RoomName);
      client.print("</h1><a href=\"/SWITCH=");
      if(relayState == HIGH)
      {
         client.print("OFF");
      }
      else
      {
         client.print("ON");
      }
      client.print("\" border=\"0\"><div class=\"");
      if(relayState == HIGH)
      {
         client.print("on");
      }
      else
      {
         client.print("Off");
      }
      client.print("\" id=\"switchSlider\"></div><div class=\"");
      if(relayState == HIGH)
      {
         client.print("on");
      }
      else
      {
         client.print("Off");
      }
      client.print("\" id=\"switchToggle\"></div></a><br /><br /><a href=\"/\">Refresh</a> <br /><br />Brought to you by <a href=\"http://www.gineer.co.za/\">Gineer R&D</a><p style=\"font-size: x-small;\">Rest: http://");
      client.print(WiFi.localIP());
      client.print("/SWITCH=ON or http://");
      client.print(WiFi.localIP());
      client.print("/SWITCH=OFF</p></body></html>");
      Serial.println("htmlsent");
   }
}

Friday, 22 July 2016

Lab supply progress - Rectifier board redesign

I've finally made some progress with the power supply. After re-spinning a board and twice setting my diodes on fire, I now have a working first stage.

In the video below I give you a quick run through of my work and also show the inrush current limiting board and the regulator stage.


As I've mentioned before, this power supply will also be modular, but not only in the sense that each stage will be a separate board, but even at the board level parts are optional. This allows for you to build a bare bones analogue PSU through to a fully connected lab grade power supply.

Leave comments below. :-)



Sunday, 17 July 2016

Open Source Hardware: USB-A Mounting board

while ago I tore down an old device (Can't remember if it was an old printer or something else) and found a neat little module that you could screw onto the side of a case to hold a USB-A port securely. Many designs have the USB port mounted on the main PCB but in many cases I want a USB port some distance from the main PCB which then makes it quite hard to mount it nicely.

This board, together with a quick and easy 3D printed housing, makes it a perfect solution (in my opinion anyway ;-) I've made the PCB available on thingiverse and the PCB available on OSHPark.




Get the PCB from OSHPark:

Order from OSH Park

Get the 3D Printed part from Thingiverse:

Gineer USB-a Female receptacle Case Mount

Monday, 31 August 2015

3D Printer Upgrade

Over the weekend, right in the middle of a major project, my printer started acting up (as usual). One of the issues I experienced, for the first time ever, was that my drive pulleys for my uprights were slipping.


I opted for replacing them with off the shelf aluminium pulleys with 5mm belts. The next problem I had was how to tension the belts.


After a quick search online, I found some interesting and amazing belt tensioning techniques involving some 3d printed parts. These are all good and well except that they were all a bit of over-engineering.


With a non-working printer, I had some springs from the cables I were using before, some galvanised wire and a couple of tools. From the wire I quickly bent (using long nose pliers) some loops to connect the belt to the spring as shown in the diagram below.

I then looped the belt through them. Ensuring that the teeth mesh nicely, I added a small piece of plastic on both sides (to ensure the belt is not squashed sideways) and cable tied them together. Hooking the spring now supplies dynamic self-tensioning and it all works perfectly.


In most cases, simpler is better.

One potential downside to this approach could be the fact that the belt makes such a tight turn over the loops which could be a failure point when the belt starts to perish. I'll keep you posted if that happens.


Monday, 22 June 2015

Lab Power Supply: OpAmps, Analogue Control and Digital Monitoring

I've progressed to the point where I think the second stage of the Lab Power supply is probably ready for an initial board to be made.
In this video I go through the OpAmp design, the digital monitoring, Linear control and the design of the shunt resistors in the second of three main boards in the system.

Might be time to have at least the Raw Power board manufactured so that I can progress to a stage where I can start testing the design of the second stage.

Wednesday, 27 May 2015

0-30V 0-3A Variable Bench/Lab PSU

I have started work on a Bench/Lab power supply design.



The following are Required features:
  • 0-30V variable output voltage
  • 0-3A Current Limited
  • Current Limit notification (by LED)
  • Output Enable button with notification LED
  • Display set and actual output voltage and current.
  • Static 5V output
  • Static 3.3V output
  • Display current flow of 5V and 3.3V circuits.
  • USB Charge port
  • USB PC connection port
  • PC controlled via USB
  • Internal Temperature sensor and PWM fan for quite operation.
Optional features
  • LAN Connection to connect multiple PSU's together for Parallel or Serial use or Synchronised outputs
  • Mode switch & LED for extended user interface controls
Design Requirements
  • PSU Should be fully modular to allow for expansion or alternative uses or replacement of required modules with alternatives as required.
  • PSU should be as efficient as possible
  • PSU should be as cost effective as possible
  • PSU should be as small as possible
  • PSU should be as quiet as possible

Gineer - Variable Bench PSU #1  

 

Gineer - Variable Bench PSU #2 Raw Power



Thursday, 16 April 2015

CremaBots for sale on Tindie

I have 3 more CremaBot's and have made them all available for sale on Tindie: https://www.tindie.com/products/gineer/gineer-cremabot-v2207/

I sell on Tindie

I also uploaded a full write-up of CremaBot with the Schematic, cad designs, firmware and source code.

Let me know what you guys think and get one for yourself.