Home made "Arduino with power supply" + relay board + DHT11

  • Hi,
    This is for those who can solder but making own board with SMD is to advanced 🙂 like me...maybe someday...

    Few pictures of whole set with some code for MySensors node.
    This device is to run bathroom ventilator, simply turn on and off my heating system and to measure temp & hum in the bathroom.
    System is based on Atmega 328p chip


    power supply made according to this:
    with adjustment for 230V mains.
    Used also voltage regulation board for radio and double relay board from ebay:



    now it is running over one month, box is hidden in the dry wall.
    The code:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    #define MY_NODE_ID 11 // Bathroom
    //#define MY_PARENT_NODE_ID 13
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    // Enable repeater functionality for this node
    //  Include related libraries
    #include <MySensors.h>
    #include <SPI.h>
    #include <Wire.h>
    #include <DHT.h>
    DHT dht;
    float Temp;
    float Hum;
    boolean metric = true; 
    #define DHT_PIN 2
    #define DHT_H 1
    #define DHT_T 2
    #define RELAY_1 3
    #define RELAY_2 4
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    #define NUMBER_OF_RELAYS 2 // Total number of attached relays
    MyMessage msgT1(DHT_H, V_HUM);
    MyMessage msgH1(DHT_T, V_TEMP);
    MyMessage msgR1(RELAY_1, V_STATUS);
    MyMessage msgR2(RELAY_2, V_STATUS);
    float T1;
    byte b_state=0;
    byte last_b_state=0;
    int numSensors = 0;
    boolean receivedConfig = false;
    const unsigned long tUpdate = 60000; // update interval
    unsigned long t0;
    void presentation()
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Bathroom MyS 2.1.1", "032417");
      // Fetch the number of attached temperature sensors
      present(DHT_H, S_HUM,"Hum Bath");
      present(DHT_T, S_TEMP,"Temp Bath");
      present(RELAY_1, S_BINARY, "VENT");
      present(RELAY_2, S_BINARY, "Central heating");
    void before()
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);
        // Set relay to last known state (using eeprom storage)
        digitalWrite(pin, RELAY_OFF);
    void setup()
    {  delay(1000);
      // Startup up the OneWire library
    void loop()
      if ((millis() - t0) > tUpdate) ServerUpdate(); // I believe that we can use now the Wait() command
    void ServerUpdate() {
      Hum = dht.getHumidity(); delay(50);
      Temp = dht.getTemperature();delay(50);
      send(msgT1.set(Hum, 1));
      send(msgH1.set(Temp, 1));
      t0 = millis();
    void receive(const MyMessage &message) {
      if (message.type == V_STATUS) {
        int incomingLightState =  message.getBool();
        int incomingOutlet = message.sensor;
        Serial.print("Outlet #: ");
        Serial.print("Command: ");
        if (incomingOutlet == 3) {
          if (incomingLightState == 1) {
            // Turn on  Relay1
            Serial.println("Turn off Relay 1");
            digitalWrite(incomingOutlet, incomingLightState);}
          if (incomingLightState == 0)  {
            // Turn off Ralay1
            Serial.println("Turn off Relay 1");
            digitalWrite(incomingOutlet, incomingLightState);}
        if (incomingOutlet == 4) {
          if (incomingLightState == 1) {
            // Turn on  Relay2
            Serial.println("Turn on Relay 2");
            digitalWrite(incomingOutlet, incomingLightState);}
          if (incomingLightState == 0)  {
            // Turn off Relay2
            Serial.println("Turn off Relay 2");
            digitalWrite(incomingOutlet, incomingLightState);}}

Log in to reply

Suggested Topics