Mobile App using Flutter to Turn On and Turn OFF LED through NodeMCU

This is a basic project for beginners who want to control an LED from a mobile device. Circuit is done as shown in the diagram. NodeMCU is used as the controller in Circuit.

Download the LEDcontrol library from the following link.

Unzip and copy the downloaded library to your Arduino libraries folder.

Restart Arduino software and open

File -> Examples -> LEDcontrol -> LEDcontrol

Compile and upload this program to your NodeMCU. Next is to create the android app using flutter. Necessary program files are given below.

pubspec.yaml

name: timerapp
description: A new Flutter application.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  http: ^0.12.0+4

  cupertino_icons: ^0.1.2
  flutter_timer: ^0.0.6

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:

  uses-material-design: true

main.dart

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void onLED()
{
  http.get('http://192.168.4.1/onLED');
}

void offLED()
{
  http.get('http://192.168.4.1/offLED');
}

void main() => runApp(MyApp());

class MyApp extends StatefulWidget
{
  MyApp({Key key}):super(key:key);

  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp>
{
  @override
  Widget build(BuildContext context) {

    return MaterialApp(
      title: 'LED CONTROL SYSTEM',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('LED CONTROL SYSTEM'),
          backgroundColor: Colors.teal,
        ),
        body: ListView(
          padding: EdgeInsets.all(10),
          children: <Widget>[

            RaisedButton(
              child: Text(
                'TURN ON LED',
                style: TextStyle(
                  color: Colors.white,
                ),
              ),
              padding: EdgeInsets.only(top: 15, bottom: 15),
              onPressed: onLED,
              color: Colors.green.shade900,
            ),

            Container(
              height: 10,
            ),

            RaisedButton(
                child: Text(
                  'TURN OFF LED',
                  style: TextStyle(
                    color: Colors.white,
                  ),
                ),
                padding: EdgeInsets.only(top: 15, bottom: 15),
                onPressed: offLED,
                color: Colors.pink
            ),
          ],
        ),
      ),
    );
  }
}

After creating and uploading your App to your mobile device, connect your mobile device to NodeMCU through WiFi. Now, open you newly designed App on mobile device. Press the green button to turn ON the LED and press the RED button to turn OFF the LED.

Published by

Leave a Reply

avatar
  Subscribe  
Notify of
X