Hello, house — Smart Home (Python)
This example is written twice, once for each firmware. Pick the tab that matches the firmware of your Smart Home: the tab you pick is remembered on the other examples.
Firmware 3.0 renamed the Python names a program writes, and kept none of the old ones: a Smart Home on 2.x does not know the 3.0 names, and a Smart Home on 3.0 does not know the 2.x ones. The name map lists every change. If you open the example from inside MoBot, it picks the version for the firmware of your Smart Home. If you download a file from this page, use the one in the tab for your firmware.
A guided tour of everything on the board you can see or hear. The screen draws a picture and pulls three faces, the colour light walks through the rainbow and fades, the buzzer plays three different ways, the fan spins up, and the servo opens and closes the door.
Run this first on a new Smart Home board. If every part of this works, the board is healthy and every other example is worth trying.
This is the version for a house on firmware 3.0, where the house is called
home. For a house that still runs firmware 2.x, MoBot opens the 2.x version of
this example instead.
Project for firmware 3.0: 01-hello-house.firmware-3.mobot. Open it in MoBot.
What you need
Section titled “What you need”- A MoBot Smart Home board (ESP32-S3), powered.
- Its OLED screen, RGB light, buzzer, fan and servo fitted.
- A USB cable and the serial monitor.
It takes about a minute.
What you should see and hear
Section titled “What you should see and hear”| part | what |
|---|---|
| 1 | Hello! / I am your house on the screen, then a drawing: a frame, a horizon line, a filled sun and a triangle roof |
| 1 | then three big faces — happy, sad, love — and the MoBot logo |
| 2 | the light goes red, green, blue, yellow, white — check the first one really is red! — then fades up and down in pink |
| 3 | a single A note, then four rising notes, then the victory tune while the light flashes red in time, then a short tune written inside the program |
| 4 | the fan at 30 %, 60 %, 100 %, with the screen and monitor agreeing on the number |
| 5 | the servo goes to the middle, fully closed, fully open, then glides smoothly back to the middle and sweeps twice |
| end | the colour light blinks green three times and the happy face comes back |
The colour light is the firmware check
Section titled “The colour light is the firmware check”The colour light is written red first, each from 0 to 255:
home.rgb_led.set_color(255, 0, 0) # red, green, blueThat is exactly what the board does: each lamp pin is named by the colour it really drives. If the light comes on green here, this board’s lamp is wired differently from the ones MoBot ships — tell whoever looks after the kits.
Things with no block at all
Section titled “Things with no block at all”draw_triangle()— there are blocks for lines, rectangles and circles, but not triangles. The roof in the drawing is Python only.show_emoji()andshow_logo()— the three built-in faces (happy,sad,love) and the MoBot logo can only be drawn from Python.happyis the face the board wears when it switches on.servo.move_to(),sweep(),center(),move_to_min(),move_to_max()— the block can only jump to a fixed angle.move_toglides, and you can hear the difference.
The program
Section titled “The program”This is a reading copy of the program in the project: editing it changes nothing, so open the project and edit it there.
# main.py — Hello, house (Python) (iot)## A reading copy of one file inside 01-hello-house.firmware-3.mobot.# Editing this copy changes nothing: open the project and edit it there.# This is the entry point — the board runs it as main.py.# Written for firmware 3.0; the 2.x version is 01-hello-house.main.py.
"""Hello, house - MoBot Smart Home.
A tour of everything on the board that you can see or hear: the little screen,the colour light, the buzzer, the fan and the servo.
Some of this has blocks. Quite a lot of it does not:
display.show_emoji() the face the board wears when it wakes up display.draw_triangle() there are blocks for lines, boxes and circles only buzzer.play_notes() ...well, there IS a block, but only for the tunes in its list. Here you can write your own. servo.sweep() and move_to(), center(), move_to_min(), move_to_max() fan.speed asking the fan what it is doing
And one thing that is easy to get wrong: the colour light wants RED first."""
import timefrom sounds import SEQUENCES
display = home.displaylamp = home.rgb_led
# ------------------------------------------------------------------ 1 -------# The screen. 128 dots across, 64 down, and the letters are 8 dots wide -# so a line of text can be 16 letters long and there is room for 8 lines.
print("Part 1: the screen.")display.clear()display.show_text("Hello!", 0, 0)display.show_text("I am your house", 0, 16)time.sleep(2)
display.clear()display.draw_rectangle(4, 4, 120, 56) # a frame round the edgedisplay.draw_line(4, 32, 124, 32) # a horizondisplay.draw_circle(32, 18, 10, filled=True) # a sundisplay.draw_triangle(70, 30, 100, 30, 85, 10) # a roof - no block for thistime.sleep(3)
# The three built-in faces, big. show_emoji() clears the screen first.for face in ("happy", "sad", "love"): display.show_emoji(face, scale=3) time.sleep(1.2)
display.show_logo() # the MoBot logotime.sleep(2)
# ------------------------------------------------------------------ 2 -------# The colour light. RED, GREEN, BLUE - each from 0 to 255.
print("Part 2: the colour light. Watch carefully - the first one is RED.")display.clear()
for name, r, g, b in ( ("red", 255, 0, 0), ("green", 0, 255, 0), ("blue", 0, 0, 255), ("yellow", 255, 255, 0), ("white", 255, 255, 255),): display.show_text(name, 0, 24) lamp.set_color(r, g, b) # set_color(RED, GREEN, BLUE) - in that order print(" ", name) time.sleep(0.8)
lamp.set_color(0, 0, 0)
# A slow fade, which needs a hundred little steps - not something to do with blocks.print(" fading up and down")for level in range(0, 256, 5): lamp.set_color(level, 0, level // 2) time.sleep(0.02)for level in range(255, -1, -5): lamp.set_color(level, 0, level // 2) time.sleep(0.02)
# ------------------------------------------------------------------ 3 -------# The buzzer. Three ways to make a noise.
print("Part 3: sounds.")display.clear()display.show_text("Listen...", 0, 24)
# One tone: a frequency in hertz, and how long for, in milliseconds.home.buzzer.play_tone(440, 300) # 440 Hz is the note Atime.sleep(0.2)
# A note by name. C3 up to B6, and # means sharp.for note in ("C4", "E4", "G4", "C5"): home.buzzer.play_note(note, 200)
time.sleep(0.3)
# A whole ready-made tune. This one does NOT wait - it runs on a timer while# your program carries on, which is why the light can change during it.print(" playing 'victory' while the light flashes")home.buzzer.play_notes(SEQUENCES["victory"])while home.buzzer.is_playing(): lamp.set_color(255, 0, 0) time.sleep(0.1) lamp.set_color(0, 0, 0) time.sleep(0.1)
# Your own tune: a list of (note, milliseconds).print(" and one written here")home.buzzer.play_notes([("G4", 150), ("G4", 150), ("A4", 300), ("G4", 300), ("C5", 300), ("B4", 600)])time.sleep(2.5)home.buzzer.stop()
# ------------------------------------------------------------------ 4 -------# The fan and the servo.
print("Part 4: the fan.")display.clear()for speed in (30, 60, 100): display.show_text("Fan " + str(speed) + "%", 0, 24) home.fan.set_speed(speed) print(" set", speed, "- fan says it is at", home.fan.speed) time.sleep(1.5)home.fan.off()
print("Part 5: the servo - the door.")display.clear()display.show_text("Door", 0, 24)home.servo.center() # 90 degreestime.sleep(0.6)home.servo.move_to_min() # 0 degrees - closedtime.sleep(0.6)home.servo.move_to_max() # 180 degrees - wide opentime.sleep(0.6)home.servo.move_to(90, step=2, delay_ms=25) # glide back, slowlyprint(" the servo is now at", home.servo.angle, "degrees")home.servo.sweep(60, 120, step=5, delay_ms=20, cycles=2)home.servo.center()
# Last of all, the colour light blinks green three times: the tour is over.for _ in range(3): lamp.set_color(0, 255, 0) time.sleep(0.2) lamp.set_color(0, 0, 0) time.sleep(0.2)
home.display.show_emoji("happy")print("Tour finished.")Try changing it
Section titled “Try changing it”- Draw your own house on the screen: rectangles for walls and windows, a triangle for the roof.
- Write your own tune in the
play_notes([...])at the end of part 3. Each step is("note", milliseconds); notes runC3toB6. - Make the fan speed follow the knob — see 06-doorbell for how to read it.
A guided tour of everything on the board you can see or hear. The screen draws a picture and pulls three faces, the colour light walks through the rainbow and fades, the buzzer plays three different ways, the fan spins up, and the servo opens and closes the door.
Run this first on a new Smart Home board. If every part of this works, the board is healthy and every other example is worth trying.
Project for firmware 2.x: 01-hello-house.mobot. Open it in MoBot.
What you need
Section titled “What you need”- A MoBot Smart Home board (ESP32-S3), powered.
- Its OLED screen, RGB light, buzzer, fan and servo fitted.
- A USB cable and the serial monitor.
It takes about a minute.
What you should see and hear
Section titled “What you should see and hear”| part | what |
|---|---|
| 1 | Hello! / I am your house on the screen, then a drawing: a frame, a horizon line, a filled sun and a triangle roof |
| 1 | then three big faces — happy, sad, love — and the MoBot logo |
| 2 | the light goes red, green, blue, yellow, white — check the first one really is red! — then fades up and down in pink |
| 3 | a single A note, then four rising notes, then the victory tune while the light flashes red in time, then a short tune written inside the program |
| 4 | the fan at 30 %, 60 %, 100 %, with the screen and monitor agreeing on the number |
| 5 | the servo goes to the middle, fully closed, fully open, then glides smoothly back to the middle and sweeps twice |
| end | the colour light blinks green three times and the happy face comes back |
The colour light is the firmware check
Section titled “The colour light is the firmware check”The colour light is written red first:
mobotIOT.rgb_led.write(100, 0, 0) # red, green, blueSince firmware 2.0 that is exactly what the board does: each lamp pin is named by the colour it really drives, and the Set RGB LED block passes red, green, blue in the same order. If the light comes on green here, the board is on older firmware (or the project was built with a block set from before September 2026, which swapped the two numbers to compensate) - flash the current firmware.
Two things with no block at all
Section titled “Two things with no block at all”draw_triangle()— there are blocks for lines, rectangles and circles, but not triangles. The roof in the drawing is Python only.show_emoji()— the four built-in pictures (happy,sad,love,mobot) can only be drawn from Python.happyis the face the board wears when it switches on.servo.move_to(),sweep(),center(),min(),max()— the block can only jump to a fixed angle.move_toglides, and you can hear the difference.
The program
Section titled “The program”This is a reading copy of the program in the project: editing it changes nothing, so open the project and edit it there.
# main.py — Hello, house (Python) (iot)## A reading copy of one file inside 01-hello-house.mobot.# Editing this copy changes nothing: open the project and edit it there.# This is the entry point — the board runs it as main.py.
"""Hello, house - MoBot Smart Home.
A tour of everything on the board that you can see or hear: the little screen,the colour light, the buzzer, the fan and the servo.
Some of this has blocks. Quite a lot of it does not:
oled.show_emoji() the face the board wears when it wakes up oled.draw_triangle() there are blocks for lines, boxes and circles only buzzer.play_sequence() ...well, there IS a block, but only for the 23 tunes in the list. Here you can write your own. servo.sweep() and move_to(), center(), min(), max() fan.get_speed() asking the fan what it is doing
And one thing that is easy to get wrong: the colour light wants RED first."""
import timefrom sounds import SEQUENCES
oled = mobotIOT.oledrgb = mobotIOT.rgb_led
# ------------------------------------------------------------------ 1 -------# The screen. 128 pixels across, 64 down, and the letters are 8 pixels wide -# so a line of text can be 16 letters long and there is room for 8 lines.
print("Part 1: the screen.")oled.clear_screen()oled.display_text("Hello!", 0, 0)oled.display_text("I am your house", 0, 16)time.sleep(2)
oled.clear_screen()oled.draw_rectangle(4, 4, 120, 56) # a frame round the edgeoled.draw_line(4, 32, 124, 32) # a horizonoled.draw_circle(32, 18, 10, filled=True) # a sunoled.draw_triangle(70, 30, 100, 30, 85, 10) # a roof - no block for thistime.sleep(3)
# The three built-in faces, big.for face in ("happy", "sad", "love"): oled.clear_screen() oled.show_emoji(face, scale=3) time.sleep(1.2)
oled.show_emoji("mobot", scale=1) # the big MoBot logotime.sleep(2)
# ------------------------------------------------------------------ 2 -------# The colour light. RED, GREEN, BLUE - each 0 to 100 PER CENT, not 0 to 255.
print("Part 2: the colour light. Watch carefully - the first one is RED.")oled.clear_screen()
for name, r, g, b in ( ("red", 100, 0, 0), ("green", 0, 100, 0), ("blue", 0, 0, 100), ("yellow", 100, 100, 0), ("white", 100, 100, 100),): oled.display_text(name, 0, 24) rgb.write(r, g, b) # write(RED, GREEN, BLUE) - in that order print(" ", name) time.sleep(0.8)
rgb.write(0, 0, 0)
# A slow fade, which needs 100 little steps - not something to do with blocks.print(" fading up and down")for percent in range(0, 101, 2): rgb.write(percent, 0, percent // 2) time.sleep(0.02)for percent in range(100, -1, -2): rgb.write(percent, 0, percent // 2) time.sleep(0.02)
# ------------------------------------------------------------------ 3 -------# The buzzer. Three ways to make a noise.
print("Part 3: sounds.")oled.clear_screen()oled.display_text("Listen...", 0, 24)
# One tone: a frequency in hertz, and how long for.mobotIOT.buzzer.play_sound(440, 300) # 440 Hz is the note Atime.sleep(0.2)
# A note by name. C3 up to B6, and # means sharp.for note in ("C4", "E4", "G4", "C5"): mobotIOT.buzzer.play_note(note, 200)
time.sleep(0.3)
# A whole ready-made tune. This one does NOT wait - it runs on a timer while# your program carries on, which is why the light can change during it.print(" playing 'victory' while the light flashes")mobotIOT.buzzer.play_sequence(SEQUENCES["victory"])while mobotIOT.buzzer.is_busy(): rgb.write(100, 0, 0) # red, green, blue - in that order since firmware 2.0 time.sleep(0.1) rgb.write(0, 0, 0) time.sleep(0.1)
# Your own tune: a list of (note, milliseconds).print(" and one written here")mobotIOT.buzzer.play_sequence([("G4", 150), ("G4", 150), ("A4", 300), ("G4", 300), ("C5", 300), ("B4", 600)])time.sleep(2.5)mobotIOT.buzzer.stop()
# ------------------------------------------------------------------ 4 -------# The fan and the servo.
print("Part 4: the fan.")oled.clear_screen()for speed in (30, 60, 100): oled.display_text("Fan " + str(speed) + "%", 0, 24) mobotIOT.fan.set_speed(speed) print(" set", speed, "- fan says it is at", mobotIOT.fan.get_speed()) time.sleep(1.5)mobotIOT.fan.off()
print("Part 5: the servo - the door.")oled.clear_screen()oled.display_text("Door", 0, 24)mobotIOT.servo.center() # 90 degreestime.sleep(0.6)mobotIOT.servo.min() # 0 degrees - closedtime.sleep(0.6)mobotIOT.servo.max() # 180 degrees - wide opentime.sleep(0.6)mobotIOT.servo.move_to(90, step=2, delay_ms=25) # glide back, slowlyprint(" the servo is now at", mobotIOT.servo.get_angle(), "degrees")mobotIOT.servo.sweep(60, 120, step=5, delay_ms=20, cycles=2)mobotIOT.servo.center()
# Last of all, the colour light blinks green three times: the tour is over.for _ in range(3): rgb.write(0, 100, 0) time.sleep(0.2) rgb.write(0, 0, 0) time.sleep(0.2)
oled.clear_screen()oled.show_emoji("happy")print("Tour finished.")Try changing it
Section titled “Try changing it”- Draw your own house on the screen: rectangles for walls and windows, a triangle for the roof.
- Write your own tune in the
play_sequence([...])at the end of part 3. Each step is("note", milliseconds); notes runC3toB6. - Make the fan speed follow the potentiometer — see 06-doorbell for how to read it.