BrainSense Demo

BrainSense Demo

This lesson demonstrates and tests all BrainSense kit modules, showing how simple code unifies sensors and modules for a cohesive smart home prototype.

Prerequisite

You must understand how to deal with all modules as detailed in BrainSense modules.


Swing Door System

Our home door operates through a Servo motor, and we aim to implement a smart mechanism for its movement using a PIR motion sensor. The objective is to have the door open whenever the PIR motion sensor detects an object, just like the mall doors.

@Loop
    m=DRead(3,1)    # PIR Sensor PIN 3
    Move()
Goto Loop

@Move
    If m=0:ServoSet(10,0):End
    If m=1:ServoSet(10,90):End
Return

Steam Flow Measurement

In our smart home setup, particularly in the seacoast areas, we’ve integrated a Steam Sensor to monitor steam levels. If the steam overextends predefined limits, the fan will automatically activate as a responsive measure the lights turn blue.

@Loop
    NeoClear()
    s=ARead(5)      # Steam Sensor PIN 5
    AWrite(11,0)    # DC motor
    Steam()
    NeoShow(12,4)   # NeoPixel PIN 12
Goto Loop

@Steam
    If s>70
        Awrite(11,50)
        NeoSet(0, 0, 0, 255)
        NeoSet(1, 0, 0, 255)
        NeoSet(2, 0, 0, 255)
        NeoSet(3, 0, 0, 255)
        NeoShow(12,4)
    End
Return

Fire Alarm System

A crucial safety feature in our smart home is a fire alarm system. Achieved through a flame sensor, it detects any fire flames and triggers both audible and visual alerts to ensure immediate response including the automatic opening of house doors.

@Loop
    NeoClear()
    f=DRead(4,1)    # Flame Sensor PIN 4
    Flame()
    NeoShow(12,4)   # NeoPixel PIN 12
Goto Loop

@Flame
    If f=0
        ServoSet(10,90)
        For n=400 to 500 step 5
            Beep(13,n,20)
            NeoSet(0, 255, 0, 0)
            NeoSet(1, 0, 0, 255)
            NeoSet(2, 255, 0, 0)
            NeoSet(3, 0, 0, 255)
            NeoShow(12,4)
            Wait(20)
            NeoClear()
            NeoShow(12,4)
        Next
    End
Return

Auto Lighting System

In our smart home, energy efficiency is a priority. With a photoresistor as a light sensor, we ensure optimal electricity consumption. When daylight is present outdoors, the home lights automatically turn off, and as darkness falls, the lights seamlessly switch on.

@Loop
    NeoClear()
    p=Aread(0)      # Photoresistance PIN 0
    Light()
    NeoShow(12,4)   # NeoPixel PIN 12
Goto Loop

@Light
    If p<=85:
        NeoSet(0, 255, 200, 0)
        NeoSet(1, 255, 200, 0)
        NeoSet(2, 255, 200, 0)
        NeoSet(3, 255, 200, 0)
    End
Return

Plant Watering System

Within our smart home, tending to plants is an essential thing. A soil moisture sensor measures moisture levels in our grond. If it drops below the selected level, an immediate light and sound alarm reminds us to promptly water our plants.

@Loop
    NeoClear()
    g=Aread(1)      # Moisture Sensor PIN 1
    Soil()
    NeoShow(12,4)   # NeoPixel PIN 12
Goto Loop

@Soil
    If g<30                  
        For x=100 to 150 step 50
            Beep(13,x,20)
            NeoSet(0, 255, 0, 255)
            NeoSet(1, 0, 255, 0)
            NeoSet(2, 255, 0, 255)
            NeoSet(3, 0, 255,0)
            NeoShow(12,4)
            wait(20)
            NeoClear()
            NeoShow(12,4)
            m=1
        Next
    End
Return

Smart Home Dashboard

Centralizing information is important for a better understanding of what going on in our home. the LCD screens on our microcomputers—black and white for Pulse and colorful for Rave— help us to show sensors’ values, including temperature and humidity from the DHT11 sensor. This unified display offers real-time insights into our house environment.

@Loop
    LcdClear(0)
    
    s=ARead(5)      # Steam Sensor PIN 5
    t=Temp(6,11)    # Temperature Sensor PIN 6
    u=Humidity(6,11)# Humidity Sensor PIN 6
    p=Aread(0)      # photoresistance PIN 0
    g=Aread(1)      # Moisture Sensor PIN 1

    Screen()
    
    LcdShow()
Goto Loop

@Screen
    LcdTextS("BrainSense",1,3,0,2,1)
    
    y=15
    x=5
    # drawing the lables with values 
    LcdText("STEAM= ", 1, x, y):LcdText(str(s), 1, x+60, y)
    LcdText("LIGHT= ", 1, x, y+10):LcdText(str(p), 1, x+60, y+10)
    LcdText("SOIL= ", 1, x, y+20):LcdText(str(g), 1, x+60, y+20)
    LcdText("Celsius= ", 1, x, y+30):LcdText(str(t), 1, x+60, y+30)
    LcdText("Humidity= ", 1, x, y+40):LcdText(str(u), 1, x+60, y+40)
    
Return

Smart Home Full Demo

Now we will create a fully-featured smart home experience by combining previous small demos into one system. Integrate sensors like the Steam sensor, PIR motion sensor, flame sensor, photoresistor, and soil moisture sensor with other different modules like motors lights, and sound. Utilize the LCD screens on our microcomputers for a customized dashboard, showcasing real-time values, including temperature and humidity from the DHT11 sensor. This unified code provides an overview of our BrainSense kit that represents a smart home prototype.

####### INPUTS #######
### SENSORS ###
# PIR   PIN 3 
# Flame PIN 4 
# STEAM PIN 5 
# Humid PIN 6 
# Photo PIN 0 
# Soil  PIN 1 

####### OUTPUTS #######
### MOTOTRS ###
# Servo PIN 10  
# Fan PIN 11 

### LIGHTS ####
# RGB LEds PIN 12 

### SOUNDS ###
# horn PIN 13 


@Loop
    NeoClear()
    LcdClear(0)
    
    m=DRead(3,1)    # PIR Sensor
    f=DRead(4,1)    # Flame Sensor
    s=ARead(5)      # Steam Sensor
    t=Temp(6,11)    # Temperature Sensor
    u=Humidity(6,11)# Humidity Sensor
    p=Aread(0)      # photoresistance
    g=Aread(1)      # Moisture Sensor
    AWrite(11,0)    # DC motor
    
    Screen()
    Move()
    Steam()
    Flame()
    Light()
    Soil()
    
    LcdShow()
    NeoShow(12,4)
    
Goto Loop

@Move
    If m=0:ServoSet(10,0):End
    If m=1:ServoSet(10,90):End
Return

@Steam
    If s>70
        Awrite(11,50)
        NeoSet(0, 0, 0, 255)
        NeoSet(1, 0, 0, 255)
        NeoSet(2, 0, 0, 255)
        NeoSet(3, 0, 0, 255)
        NeoShow(12,4)
    End
Return

@Flame
    If f=0
        ServoSet(10,90)
        For n=400 to 500 step 5
            Beep(13,n,20)
            NeoSet(0, 255, 0, 0)
            NeoSet(1, 0, 0, 255)
            NeoSet(2, 255, 0, 0)
            NeoSet(3, 0, 0, 255)
            NeoShow(12,4)
            Wait(20)
            NeoClear()
            NeoShow(12,4)
        Next
    End
Return

@Light
    If p<=85:
        NeoSet(0, 255, 200, 0)
        NeoSet(1, 255, 200, 0)
        NeoSet(2, 255, 200, 0)
        NeoSet(3, 255, 200, 0)
    End
Return

@Soil
    If g<30                   
        For x=100 to 150 step 50
            Beep(13,x,20)
            NeoSet(0, 255, 0, 255)
            NeoSet(1, 0, 255, 0)
            NeoSet(2, 255, 0, 255)
            NeoSet(3, 0, 255,0)
            NeoShow(12,4)
            wait(20)
            NeoClear()
            NeoShow(12,4)
        Next
    End
Return

@Screen
    LcdTextS("BrainSense",1,3,0,2,1)
    
    y=15
    x=5
    # drawing the lables with values 
    LcdText("STEAM= ", 1, x, y):LcdText(str(s), 1, x+60, y)
    LcdText("LIGHT= ", 1, x, y+10):LcdText(str(p), 1, x+60, y+10)
    LcdText("SOIL= ", 1, x, y+20):LcdText(str(g), 1, x+60, y+20)
    LcdText("Celsius= ", 1, x, y+30):LcdText(str(t), 1, x+60, y+30)
    LcdText("Humidity= ", 1, x, y+40):LcdText(str(u), 1, x+60, y+40)
    
Return

What’s Next?

Can you make with a colorful BrainPad Rave LCD a better dashboard that shows the values of sensors in the shape of dynamics bars instead of using the numbers and making each sensor value with a suitable color?


BrainStorm

Explore innovative ways to amplify the impact of our sensors and seamlessly integrate them with modules like motors, sounds, and lights. Consider dynamic automation scenarios to create responsive and immersive experiences, ensuring the maximum and effective utilization of our smart home technology.

Content Licensing
Newsletter

Twitter Feed
Hot off the press!
January 30, 2024
December 14, 2023
December 11, 2023
December 8, 2023
November 24, 2023